package main

import (
	"net/http"
	"time"

	"main/comm"
	c "main/controller"
	"main/route"

	"github.com/golang/glog"
)

func tokenSync() {
	// example to show how share variable between http.server and goroutine
	for i := 1; i < 10000; i++ {
		c.ChToken <- i
		time.Sleep(time.Second * 2)
	}
}

func main() {
	comm.LogInit(1024*1024*10, 3, false, "WARNING", 2, ".")

	comm.DBPrepare("account")
	comm.DBSync("account")
	comm.TestDataInit()

	router := route.NewRouter()

	go tokenSync()

	svr := http.Server{
		Addr:           ":8080",
		Handler:        router,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	glog.Info("begin...")

	glog.Fatal(svr.ListenAndServe())
}
